<template>
  <view class="page-body">
    <view v-if="listData.length" class="list">
      <view class="item flex u-p-20" v-for="(item, i) in listData" :key="i">
        <view class="iconfont icon-consumption-fill"></view>

        <view class="u-m-l-20 flex-w-1">
          <view class="flex-x-sb u-m-b-10">
            <text class=""> {{ item.source_name }} </text>
            <text class="font-w-600 u-font-32">
              {{ item.type ? "-" : "+" }} {{ item.money }}
            </text>
          </view>
          <view class="flex-x-sb u-m-b-10">
            {{ item.source_desc }}
          </view>

          <view class="flex-x-sb u-m-b-10">
            <text class="u-font-24 color-999">
              {{ item.order_no || "-" }}
            </text>
            <text
              v-if="type == 'service-home' && item.worker_is_price"
              style="color: #f0250e"
            >
              {{ item.worker_is_price == 0 ? "未发放" : "已发放" }}
            </text>
          </view>
          <view class="flex-x-sb u-m-b-10 color-999">
            <text class="u-font-24">
              生成时间：{{
                $utils.turnDate(item.created_at * 1000, "yyyy-mm-dd")
              }}
            </text>
            <text class=""> </text>
          </view>
        </view>
      </view>
      <view class="u-p-b-20 u-p-t-20">
        <u-loadmore :status="loadmoreStatus"></u-loadmore>
      </view>
    </view>
    <u-empty v-else mode="data"></u-empty>
  </view>
</template>
<script>
import { profitList } from "@/api/service-home";
export default {
  data() {
    return {
      listData: [],
      page: {
        page: 1,
        pageSize: 10,
        count: 0
      },
      loadmoreStatus: "loadmore",
      type: "", //service-home服务到家
      is_price_no: "" //service-home是否已发放
    };
  },
  onLoad(params) {
    this.type = params.type || "";
    this.is_price_no = params.is_price_no || "";
    this.loadData();
  },
  onShow() {},
  methods: {
    async loadData(reset, fn) {
      if (reset) {
        let { listData, loadmoreStatus, page } = this.$options.data();
        this.page = page;
        this.listData = listData;
        this.loadmoreStatus = loadmoreStatus;
      }
      if (this.loadmoreStatus == "nomore") return;
      var res;
      if (this.type == "service-home") {
        res = await profitList(
          { ...this.page, is_price_no: this.is_price_no },
          true
        );
      } else {
        res = await this.$allrequest.share.getUserShareMoney(this.page, true);
      }
      this.listData.push(...res.data.data);
      this.loadmoreStatus = res.data.data.length < 10 ? "nomore" : "loadmore";
      this.page.page++;
      fn && fn();
    }
  },
  computed: {},
  watch: {},
  onReachBottom() {
    this.loadData();
  },
  onPullDownRefresh() {
    this.loadData(true, () => uni.stopPullDownRefresh());
  }
};
</script>
<style lang="scss" scoped>
.page-body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  .item {
    border-bottom: 1px solid #f5f5f5;
    &:nth-child(1) {
      border: 0;
    }
    .icon-consumption-fill {
      font-size: 50rpx;
      color: #fff;
      width: 70rpx;
      height: 70rpx;
      line-height: 70rpx;
      text-align: center;
      background: #fec121;
      border-radius: 50%;
    }
  }
}
</style>
